/**
 * jQuery Validate  验证 
 */

var validaten = {}

validaten.init = function() {
	// 初始化表单校验
	validaten.initValidate();
}


validaten.submitAdd = function() {
	$("#validaten-form-addvalidaten").submit();
}



/**
 * 自定义表单验证
 * 验证手机号 和 密码
 */
jQuery.validator.addMethod("isPhone",function(value,element){
	var phone = /^1[34578]\d{9}$/;
	return this.optional(element)|| phone.test(value);},
	"请输入正确的手机号码");

jQuery.validator.addMethod("isPassword",function(value,element){
	var password = /^(?=.*\d)[A-Za-z]\w{5,9}/;
	return this.optional(element)|| password.test(value);},
	"请输入正确的密码格式");
/**
 * 初始化表单校验
 */
validaten.initValidate = function() {// jQuery Validate
	$("#validaten-form-addvalidaten").validate({
		rules : {
			name : {
				required : true,
				rangelength : [6,12]
			},
			password : {
				required : true,
				isPassword : true
			},
			phone : {
				required : true,
				isPhone : true
			},
			email : {
				required : true,
				email : true
			}
		},
		messages : {},
		submitHandler : function(form) {// 校验通过后执行
			validaten.submitAddForm(form);
			return false;
		}
	});
}

validaten.submitAddForm = function(form) {
	var url = "validate";
	var form =new FormData(document.getElementById("validaten-form-addvalidaten"));  
	$.ajax({
		url : url,
		method : "post",
		data : form,
		 async: true,  
         cache: false,  
		processData : false,
		contentType : false,
		success : function(data) {// 获取查询结果客户集合
			if (data == 1) {
				alert("成功！")
			} else {
				alert("失败！")
			}
		}
	});
}

